from framwork.common.tools  import open_browsers
from time import sleep
from selenium.webdriver.common.by import By

"""添加邮件模版 ok"""
#数据
url=r"http://192.168.1.36/crm/index.php?m=user&a=login"
user_name="admin"
passwd="123456"
name="国庆模版"
title="国庆快乐"
text="红旗飘扬庆华章，山河锦绣万里芳。愿你国庆假期，心怀家国，眼有光芒，步履所至皆欢笑，岁月赠你皆安康。祝祖国繁荣昌盛，祝你国庆快乐！"
#定位器
username_locator=(By.NAME,"name")
password_locator=(By.NAME,"password")
login_btn_locator=(By.NAME,"submit")
gd_locator=(By.LINK_TEXT,"更多")
yx_locator=(By.LINK_TEXT,"营销")
email_locator=(By.LINK_TEXT,"发送邮件")
addemail_locator=(By.CSS_SELECTOR,"body > div.container > div.row > div:nth-child(2) > form > div > div:nth-child(2) > p > a:nth-child(4)")
addmodel_locator=(By.ID,"add")
namemodel_locator=(By.CSS_SELECTOR,"#dialog-add > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > input")
title_locator=(By.CLASS_NAME,"span4")
text_locator=(By.NAME,"content")
btn_locator=(By.NAME,"submit")
#操作
driver=open_browsers()
driver.get(url)
sleep(3)
driver.find_element(*username_locator).send_keys(user_name)
driver.find_element(*password_locator).send_keys(passwd)
driver.find_element(*login_btn_locator).click()
sleep(1)
driver.find_element(*gd_locator).click()
driver.find_element(*yx_locator).click()
driver.find_element(*email_locator).click()
driver.find_element(*addemail_locator).click()
driver.find_element(*addmodel_locator).click()
driver.find_element(*namemodel_locator).send_keys(name)
driver.find_element(*title_locator).send_keys(title)
driver.find_element(*text_locator).send_keys(text)
driver.find_element(*btn_locator).click()
sleep(1)
#退出浏览器
sleep(3)
driver.close()